package ModelLayer;
import java.util.ArrayList;

import ExceptionsPackage.IdNotFoundException;

public class SaleCon
{
	private static SaleCon instance;
    private ArrayList<Sale> saleCon;
    
    public static SaleCon getInstance()
    {
        if(instance == null)
        {
            instance = new SaleCon();
        }
        return instance;
    }
    
    private SaleCon()
    {
        saleCon = new ArrayList<Sale>();
    }
    
    public ArrayList<Sale> getSaleCon()
    {
        return saleCon;
    }
    
    public Sale getSale(int id)
    {
    	boolean found = false;
        int i = 0;
        while(i < saleCon.size() && !found)
        {
        	if(saleCon.get(i).getId() == id)
        	{
                found = true;
            }
            else
            {
                i ++;
            }
        }
        if(found)
        {
        	return saleCon.get(i);
        }
        else
        {
        	return null;
        }
    }
    
    public void addSale(Sale sale)
    {
        saleCon.add(sale);
    }
    
    public void removeSale(int id)
    {
        Sale tempSale = getSale(id);
        if(tempSale != null)
        {
            saleCon.remove(tempSale);
        }
    }
}
